home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / DOCKING.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  15KB  |  461 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. // $Revision:   10.22  $
  6. //
  7. // TDockable classes: TDockableGadgetWindow & TDockableControlBar
  8. // TDockingSlip classes: TFloatingSlip & TEdgeSlip
  9. // and the THarbor docking manager
  10. //----------------------------------------------------------------------------
  11. #if !defined(OWL_DOCKING_H)
  12. #define OWL_DOCKING_H
  13.  
  14. #if !defined(OWL_DECFRAME_H)
  15. # include <owl/decframe.h>
  16. #endif
  17. #if !defined(OWL_FLOATFRA_H)
  18. # include <owl/floatfra.h>
  19. #endif
  20. #if !defined(OWL_GADGETWI_H)
  21. # include <owl/gadgetwi.h>
  22. #endif
  23. #if !defined(OWL_CONTROLB_H)
  24. # include <owl/controlb.h>
  25. #endif
  26.  
  27. #if defined(BI_NAMESPACE)
  28. namespace OWL {
  29. #endif
  30.  
  31. // Generic definitions/compiler options (eg. alignment) preceeding the
  32. // definition of classes
  33. #include <services/preclass.h>
  34.  
  35. class _OWLCLASS THarbor;
  36.  
  37. //
  38. // General use 2-D rectangular relative position enum
  39. //
  40. // Used here to described the location of a docking window [more specifically
  41. // the location of the EdgeSlip containing docking windows].
  42. //
  43. // NOTE: This enumeration corresponds to the TLocation enumeration of
  44. //       TDecoratedFrame.
  45. //
  46. enum TRelPosition {
  47.   rpNone,                       // No location specified
  48.   rpAbove,                      // Refers to top edge of frame
  49.   rpBelow,                      // Refers to bottom edge of frame
  50.   rpRightOf,                    // Refers to left edge of frame
  51.   rpLeftOf                      // Refers to right edge of frame
  52. };
  53.  
  54. //
  55. // class TDockable
  56. // ~~~~~ ~~~~~~~~~
  57. // Abstract base class for windows that want to be dockable into docking slips-
  58. // either fixed or floating docking windows.
  59. //
  60. class _OWLCLASS TDockable {
  61.   public:
  62.     // Return the rectangle of the dockable window in the given location.
  63.     // The dockable chooses its layout (horizontal, vertical or rectangle) in
  64.     // that position.
  65.     //
  66.     virtual TSize ComputeSize(TAbsLocation loc, TSize* dim) = 0;
  67.     virtual void  GetRect(TRect& rect) = 0;
  68.  
  69.     // Change the window to be equal to the size returned from ComputeNNNNN.
  70.     //
  71.     virtual void  Layout(TAbsLocation loc, TSize* dim=0) = 0;
  72.  
  73.     // This is overriden for any window that wants to be docked. This routine
  74.     // is called from an LButtonDown to determine if the mouse down should move
  75.     // the window or perform an action within the docked window. For example if
  76.     // a gadget window is docked then this routine would decide if the
  77.     // mousedown is on an enabled gadget then the control is not be moved but
  78.     // the action of the gadget being depressed done. Otherwise, the gadget
  79.     // window would be moved within the docking window.
  80.     //
  81.     virtual bool  ShouldBeginDrag(TPoint& pt) = 0;
  82.  
  83.     virtual TWindow* GetWindow() = 0;
  84.     virtual THarbor* GetHarbor() = 0;
  85. };
  86.  
  87. //
  88. // class TDockableGadgetWindow
  89. // ~~~~~ ~~~~~~~~~~~~~~~~~~~~~
  90. // A version of TGadgetWindow which is dockable
  91. //
  92. class _OWLCLASS TDockableGadgetWindow : public TGadgetWindow, public TDockable {
  93.   public:
  94.     TDockableGadgetWindow(TWindow*        parent = 0,
  95.                           TTileDirection  direction = Horizontal,
  96.                           TFont*          font = new TGadgetWindowFont,
  97.                           TModule*        module = 0);
  98.    ~TDockableGadgetWindow();
  99.  
  100.     // Override TDockable virtuals
  101.     //
  102.     TSize    ComputeSize(TAbsLocation loc, TSize* dim);
  103.     void     GetRect(TRect& rect);
  104.     void     Layout(TAbsLocation loc, TSize* dim=0);
  105.     bool     ShouldBeginDrag(TPoint& pt);
  106.     TWindow* GetWindow();
  107.     THarbor* GetHarbor();
  108.  
  109.     // Override TGadgetWindow virtuals
  110.     //
  111.     virtual void LayoutSession();
  112.  
  113.   protected:
  114.     void          EvLButtonDown(uint modKeys, TPoint& point);
  115.  
  116.     // Returns the layout direction to use when placed in a slip
  117.     // This can be overridden to provide different docking behaviour
  118.     //
  119.     virtual TTileDirection GetDirectionForLocation(TAbsLocation loc);
  120.  
  121.   DECLARE_RESPONSE_TABLE(TDockableGadgetWindow);
  122. };
  123.  
  124. //
  125. // class TDockableControlBar
  126. // ~~~~~ ~~~~~~~~~~~~~~~~~~~
  127. // A control bar class that is dockable
  128. //
  129. class _OWLCLASS TDockableControlBar : public TDockableGadgetWindow {
  130.   public:
  131.     TDockableControlBar(TWindow*        parent = 0,
  132.                         TTileDirection  direction = Horizontal,
  133.                         TFont*          font = new TGadgetWindowFont,
  134.                         TModule*        module = 0);
  135.  
  136.   DECLARE_CASTABLE;
  137. };
  138.  
  139. //
  140. // class TDockingSlip
  141. // ~~~~~ ~~~~~~~~~~~~
  142. // Abstract base class for windows which accept & hold dockable windows.
  143. //
  144. class _OWLCLASS TDockingSlip {
  145.   public:
  146.     // These are overriden for any window that wants to be notified on dockable
  147.     // windows being moved or removed.
  148.     //
  149.     virtual void DockableInsert(TDockable& dockable, const TPoint* topLeft=0,
  150.                                 TRelPosition position=rpNone, TDockable* relDockable=0) = 0;
  151.     virtual void DockableMove(TDockable& dockable, const TPoint* topLeft=0,
  152.                               TRelPosition position=rpNone, TDockable* relDockable=0) = 0;
  153.     virtual void DockableRemoved(const TRect& orgRect) = 0;
  154.  
  155.     virtual TAbsLocation GetLocation() const = 0;
  156.  
  157.     // Called by Harbor to initialize back pointer
  158.     //
  159.     void     SetHarbor(THarbor* harbor);
  160.     THarbor* GetHarbor() const;
  161.  
  162.   protected:
  163.     THarbor* Harbor;
  164. };
  165.  
  166. //
  167. // class TFloatingSlip
  168. // ~~~~~ ~~~~~~~~~~~~~
  169. // A floating frame which can hold a dockable window. Is also dockable in order
  170. // to act as a proxy for its held dockable when dragging.
  171. //
  172. class _OWLCLASS TFloatingSlip : public TFloatingFrame,
  173.                                 public TDockingSlip, public TDockable
  174. {
  175.   public:
  176.     TFloatingSlip(TWindow*        parent,
  177.                   int x, int y,
  178.                   TWindow*        clientWnd = 0,
  179.                   bool            shrinkToClient = true,
  180.                   int             captionHeight = DefaultCaptionHeight,
  181.                   bool            popupPalette = true,  // false?
  182.                   TModule*        module = 0);
  183.  
  184.     // Override TDockingSlip virtuals
  185.     //
  186.     void     DockableInsert(TDockable& dockable, const TPoint* topLeft,
  187.                             TRelPosition position, TDockable* relDockable);
  188.     void     DockableMove(TDockable& dockable, const TPoint* topLeft,
  189.                           TRelPosition position, TDockable* relDockable);
  190.     void     DockableRemoved(const TRect& orgRect);
  191.  
  192.     TAbsLocation GetLocation() const;
  193.  
  194.     // Override TDockable virtuals
  195.     //
  196.     TSize    ComputeSize(TAbsLocation loc, TSize* dim);
  197.     void     GetRect(TRect& rect);
  198.     void     Layout(TAbsLocation loc, TSize* dim=0);
  199.     bool     ShouldBeginDrag(TPoint& pt);
  200.     TWindow* GetWindow();
  201.     THarbor* GetHarbor();
  202.  
  203.   protected:
  204.     void    EvNCLButtonDown(uint hitTest, TPoint& point);
  205.     void    EvLButtonDown(uint hitTest, TPoint& point);
  206.     bool    EvSizing(uint side, TRect& rect);
  207.     void    EvWindowPosChanging(WINDOWPOS far& windowPos);
  208.     void    EvWindowPosChanged(WINDOWPOS far& windowPos);
  209.     void    EvClose();
  210.     void    EvWinIniChange(char far*);
  211.     void    EvGetMinMaxInfo(MINMAXINFO far& info);
  212.  
  213.   DECLARE_RESPONSE_TABLE(TFloatingSlip);
  214. };
  215.  
  216. enum TGridType {   // Grid type corresponds with Location:
  217.   YCoord,            // Top & bottom edge have Y coords parallel horiz
  218.   XCoord,            // Left & right edge have X coords parallel vertically
  219. };
  220.  
  221. //
  222. // Stuff for edge slip managing the dockable layout.
  223. //
  224. template <class T> class TFastList {
  225.   public:
  226.     TFastList(int initSize = 10, int deltaGrowth = 10, bool sorted = true,
  227.               bool unique = true);
  228.    ~TFastList();
  229.  
  230.     bool Add(uint32 comparison, T* object);
  231.     bool Add(uint32 comparison, T object);
  232.     T*   Remove(uint32 comparison);
  233.     T*   RemoveEntry(int index);
  234.     int  FindEntry(uint32 comparison);    // Find an object with the comparison return it's index.
  235.     T&   GetEntry(int index);             // Return the object.
  236.  
  237.     int  Count() const;                   // The count of entries in list
  238.  
  239.     void Clear();     
  240.     T& operator [](int i);
  241.  
  242.     void Fill(TWindow* parent, TGridType gridType);
  243.  
  244.   private:
  245.     void Grow(int minNewSize);
  246.     void OpenUpSpace(int index);
  247.     void CloseUpSpace(int index);
  248.  
  249.     int   Delta;
  250.     bool  SortEntries;
  251.     bool  UniqueEntries;
  252.  
  253.     struct TDatum {
  254.       uint32 CompareItem;
  255.       T*     Object;
  256.     };
  257.  
  258.     TDatum* DataPtr;
  259.     int     SpaceCount;
  260.     int     EntryCount;
  261. };
  262.  
  263. //
  264. // class TEdgeSlip
  265. // ~~~~~ ~~~~~~~~~
  266. // The class of windows used by THarbor as the actual docking slips
  267. // along the decorated frame's client's edges
  268. //
  269. class _OWLCLASS TEdgeSlip : public TWindow, public TDockingSlip {
  270.   public:
  271.     TEdgeSlip(TDecoratedFrame& parent, TAbsLocation location, TModule* module = 0);
  272.  
  273.     // Overridden TWindow virtuals
  274.     //
  275.     TResult  EvCommand(uint id, THandle hWndCtl, uint notifyCode);
  276.     void     EvCommandEnable(TCommandEnabler& commandEnabler);
  277.     void     SetupWindow();
  278.  
  279.     // Overridden TDockingSlip virtuals
  280.     //
  281.     void     DockableInsert(TDockable& dockable, const TPoint* topLeft,
  282.                             TRelPosition position, TDockable* relDockable);
  283.     void     DockableMove(TDockable& dockable, const TPoint* topLeft,
  284.                           TRelPosition position, TDockable* relDockable);
  285.     void     DockableRemoved(const TRect& orgRect);
  286.  
  287.     TAbsLocation GetLocation() const;
  288.  
  289.     // Called by Harbor when creating this docking window on a drop
  290.     //
  291.     void     ReLayout(bool forcedLayout);
  292.  
  293.   protected:
  294.     void     EvLButtonDown(uint modKeys, TPoint& point);
  295.     void     EvLButtonDblClk(uint modKeys, TPoint& point);
  296.     uint     EvNCCalcSize(bool calcValidRects, NCCALCSIZE_PARAMS far& calcSize);
  297.  
  298. #if defined(BI_PLAT_WIN32)
  299.     void     EvNCPaint(HRGN);
  300. #else
  301.     void     EvNCPaint();
  302. #endif //BI_PLAT_WIN32
  303.  
  304.     bool     EvEraseBkgnd(HDC);
  305.     void     EvParentNotify(uint event, uint childHandleOrX, uint childIDOrY);
  306.     void     EvWindowPosChanging(WINDOWPOS far& windowPos);
  307.  
  308.     // Internal dockable tiling support
  309.     //
  310.     void     CompressGridLines();
  311.     void     CompressParallel(int width);
  312.     TSize    ComputeDockingArea();
  313.  
  314.     TWindow* MoveDraggedWindow(TWindow* draggedWindow);
  315.     void     MoveAllOthers(TWindow* draggedWindow, TWindow* movedWindow);
  316.  
  317.     int      GridSize(int baseCoord);
  318.  
  319.   protected_data:
  320.     TAbsLocation    Location;     // Location on the frame
  321.     TGridType       GridType;     // Type of grid
  322.  
  323.   DECLARE_RESPONSE_TABLE(TEdgeSlip);
  324. };
  325.  
  326. //
  327. // class THarbor
  328. // ~~~~~ ~~~~~~~
  329. // The object that holds all the docking slips. It performs the actual docking
  330. // insertion & coordination. Is never visible, but is a window in order to
  331. // capture the mouse.
  332. //
  333. class _OWLCLASS THarbor : public TWindow {
  334.   public:
  335.     THarbor(TDecoratedFrame& df);
  336.    ~THarbor();
  337.  
  338.     // Dockable window insertion
  339.     //
  340.     TDockingSlip*   Insert(TDockable& dockable,
  341.                            TAbsLocation location,
  342.                            const TPoint* where = 0,
  343.                            TRelPosition position = rpNone,
  344.                            TDockable* relativeTo = 0);
  345.  
  346.     // Move a dockable from one slip to another, programatically
  347.     //
  348.     void            Move(TDockable& dockable,
  349.                          TAbsLocation location,
  350.                          const TPoint* where = 0,
  351.                          TRelPosition position = rpNone,
  352.                          TDockable* relativeTo = 0);
  353.  
  354.     // Remove a dockable from the harbor
  355.     //
  356.     void            Remove(TDockable& dockable);
  357.  
  358.     // Called by docking slips
  359.     //
  360.     bool            DockDraggingBegin(TDockable& dockable, TPoint& pt,
  361.                                       TAbsLocation location,
  362.                                       TDockingSlip* dockingNotify = 0);
  363.  
  364.   protected:
  365.     void            SetupWindow();
  366.  
  367.     TEdgeSlip*      GetEdgeSlip(TAbsLocation location);
  368.     void            SetEdgeSlip(TAbsLocation location, TEdgeSlip* slip);
  369.     TRelPosition    GetSlipPosition(TAbsLocation location);
  370.  
  371.     // Factory members - could be overridden by derived THarbor class
  372.     //
  373.     virtual TEdgeSlip* ConstructEdgeSlip(TDecoratedFrame& df,
  374.                                          TAbsLocation location);
  375.     virtual TFloatingSlip* ConstructFloatingSlip(TDecoratedFrame& df,
  376.                                                  int x, int y,
  377.                                                  TWindow* dockableWindow);
  378.  
  379.     // Mouse handlers - invoked when harbor grabs capture
  380.     //
  381.     void     EvMouseMove(uint modKeys, TPoint& point);
  382.     void     EvLButtonUp(uint modKeys, TPoint& point);
  383.     void     EvLButtonDblClk(uint modKeys, TPoint& point);
  384.  
  385.   private:
  386.     TDecoratedFrame&  DecFrame;
  387.  
  388.     // Docking slip windows
  389.     //
  390.     TEdgeSlip*   SlipTop;
  391.     TEdgeSlip*   SlipLeft;
  392.     TEdgeSlip*   SlipBottom;
  393.     TEdgeSlip*   SlipRight;
  394.  
  395.     // Dockable dragging state. Put into a struct packet
  396.     //
  397.     TDockable*    DragDockable;
  398.     TWindowDC*    DragDC;
  399.     TAbsLocation  DragOrgSlipLoc;  // Original slip location on mouseDown.
  400.     TAbsLocation  DragSlipLoc;
  401.     TRect         DragFrame;
  402.     TSize         DragVSize;       // Size of dockable when vertical
  403.     TSize         DragHSize;       // Size of dockable when horizontal
  404.     TSize         DragNSize;       // Size of dockable when a natural shape
  405.     TPoint        DragAnchor;
  406.     TDockingSlip* DragNotificatee; // Slip notified on drag operations
  407.  
  408.     TRect         SlipTR;
  409.     TRect         SlipBR;
  410.     TRect         SlipLR;
  411.     TRect         SlipRR;
  412.  
  413.   DECLARE_RESPONSE_TABLE(THarbor);
  414. };
  415.  
  416. // Generic definitions/compiler options (eg. alignment) following the
  417. // definition of classes
  418. #include <services/posclass.h>
  419.  
  420. #if defined(BI_NAMESPACE)
  421. } // namespace OWL
  422. #endif
  423.  
  424. //----------------------------------------------------------------------------
  425. // Inline implementations
  426. //
  427.  
  428. //
  429. // Set the back pointer to the harbor.
  430. //
  431. inline void TDockingSlip::SetHarbor(THarbor* harbor)
  432. {
  433.   Harbor = harbor;
  434. }
  435.  
  436. //
  437. // Retrieve the associated harbor.
  438. //
  439. inline THarbor* TDockingSlip::GetHarbor() const
  440. {
  441.   return Harbor;
  442. }
  443.  
  444. //
  445. // Return the count of layouts.
  446. //
  447. template <class T>
  448. inline int TFastList<T>::Count() const
  449. {
  450.   return EntryCount;
  451. }
  452.  
  453. //
  454. // Retrieve the indexed layout.
  455. //
  456. template <class T>
  457. inline T& TFastList<T>::operator [](int i) {
  458.   return GetEntry(i);
  459. }
  460. #endif  // OWL_DOCKING_H
  461.